[test-improver] Improve tests for config package#413
Merged
Conversation
- Replace manual error checking with assert.ErrorContains() - Use t.Setenv() for automatic cleanup instead of defer os.Unsetenv() - Add setupStdinTest() helper to reduce boilerplate - Remove unused strings import - Add 9 new edge case tests for better coverage - Convert all tests to use testify best practices
This was referenced Jan 22, 2026
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Improvements: validation_test.go
File Analyzed
internal/config/validation_test.gointernal/configImprovements Made
1. Better Testing Patterns ✅
strings.Contains()error checks withassert.ErrorContains()os.Setenv()/defer os.Unsetenv()tot.Setenv()for automatic cleanupassert.Equal()setupStdinTest()helper function to reduce boilerplate from ~10 lines to 1-2 lines per teststringsimport after refactoringrequire.Error()for critical assertions2. Increased Coverage ✅
/path/${VAR1}/subdir/${VAR2}LoadFromStdin()mcpServersmapcontainerfield (TestLoadFromStdin_VariableExpansionInContainer)Coverage Improvement:
3. Cleaner & More Stable Tests ✅
setupStdinTest()helpert.Helper()for better test failure reportingdefert.Setenv()(Go 1.17+)defer os.Unsetenv()callsrequire.Error()for critical checks (stops test on failure)assert.ErrorContains()for error message validationassert.Equal()for value comparisonsCode Quality Metrics
Before:
After:
Test Execution
All improvements maintain 100% backward compatibility with existing tests. The changes are focused on:
Why These Changes?
This test file was selected based on analysis showing:
strings.Contains()patternsThe improvements make the test suite:
Generated by Test Improver Workflow
Focuses on better testify patterns, increased coverage, and more stable tests